package com.katze.boot.plugins.security.annotations;

import org.springframework.core.annotation.AliasFor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import java.lang.annotation.*;

@Target({ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
@Documented
@RequestMapping
@PreAuthorize("@ps.toAuthority(#root)")
public @interface RestRequestMapping {
    /**
     * 指定请求的实际地址，指定的地址可以是URI Template 模式
     * @1.普通的具体值
     *  @RequestMapping(value = "/list")
     *  @RequestMapping(value = {"","/page","page*"})
     * @2.含有某变量的一类值(URI Template Patterns with Path Variables)
     *  @RequestMapping(value = "/list/{communityId}")
     * @3.含正则表达式的一类值( URI Template Patterns with Regular Expressions)
     *  @RequestMapping(value = "/list/{communityId:[a-z-]+}-{version:\d\.\d\.\d}.{extension:\.[a-z]}")
     */
    @AliasFor(attribute = "value", annotation = RequestMapping.class)
    String[] value() default {};

    /**
     * 指定请求的method类型， GET、POST、PUT、DELETE等
     * @例如：RequestMapping(value = "/list" , method = RequestMethod.POST)
     */
    @AliasFor(attribute = "method", annotation = RequestMapping.class)
    RequestMethod[] method() default { RequestMethod.GET };

    @AliasFor(annotation = RequestMapping.class)
    String[] produces() default {};

    /**
     * 请求权限
     */
    String[] permits() default "";

    /**
     * 多权限逻辑符
     */
    Logical logical() default Logical.AND;

    /**
     * 接口描述
     */
    String description() default "";

    /**
     * AOP是否拦截
     */
    boolean skip() default false;
}
